#include <stdio.h>
#include <stdlib.h>
#include "BinaryTree.h"
#include "Set.h"

struct Set
{
    BSTree *tree;
    int (*Campare)(ElementType,ElementType);
    void (*Travel)(ElementType);
    int (*Find)(ElementType,ElementType);
};

set* InitSet(int (*Campare)(ElementType,ElementType),void (*Travel)(ElementType), int (*Find)(ElementType,ElementType))
{
    set *s = (set*)malloc(sizeof(set));
    if(s == NULL)
        return NULL;

    s->tree = InitBSTree();
    s->Campare = Campare;
    s->Travel = Travel;
    s->Find = Find;
    return s;
}

void InsertSet(set *s, ElementType element)
{
    InsertElement(s->tree,element,s->Campare);
}

void TravelSet(set *s)
{
    TravelMid(s->tree,s->Travel);
}

ElementType FindSet(set *s, ElementType element)
{
    ElementType *temp = GetNodeData(FindByElement(s->tree,element,s->Find));
    if(temp == NULL)
        return NULL;
    return temp;
}

void RemoveSetByElement(set *s, ElementType element)
{
    RemoveByElement(s->tree,element, s->Find);
}

int GetSize(set *s)
{
    return GetNodeNumber(s->tree);
}